#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> dif(n + 1, 0);
	while (q--)
	{
		int l, r;
		cin >> l >> r;
		dif[l - 1]++;
		dif[r]--;
	}
	dif.pop_back();
	for (int i = 1; i < n; i++) dif[i] += dif[i - 1];
	sort(dif.begin(), dif.end(), greater<int>());
	sort(a.begin(), a.end(), greater<int>());
	int ans = 0;
	for (int i = 0; i < n; i++) ans += dif[i] * a[i];
	cout << ans;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	//cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}